<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" id="myinput">
    <br>
    <div id="mydiv">1111</div>
    <br>
    <button id="mybtn1">提交get</button>
    <br>
    <button id="mybtn2">提交post</button>

    <script>
        let mybtn1 = document.getElementById("mybtn1");
        mybtn1.addEventListener("click",()=>{
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                  if(xhr.status==200){
                      document.querySelector("#mydiv").innerHTML=xhr.responseText;
                  }
                }
            }
            let user = document.getElementById("myinput").value;

            // xhr.open("GET", "ajaxrequest?user"+user+"&t="+new Date().getTime(), true)
            xhr.open("GET", "ajaxrequest?user="+user+"&t=" + new Date().getTime(), true);
            xhr.send();
        })

        let mybtn2 = document.getElementById("mybtn2");
        mybtn2.addEventListener("click",()=>{
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    document.querySelector("#mydiv").innerHTML=xhr.responseText;
                }
            }
            xhr.open("post", "ajaxrequest?", true)
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            let user = document.querySelector("#myinput").value;
            xhr.send("user="+user);
        })
    </script>
</body>
</html>